//
// Created by jerry on 2024/6/5.
//
#include "sort.h"
void InsertSort(SqList list)
{
    int i, j;
    for (i = 2; i <= list.length; i++)
    {
        if (list.r[i] >= list.r[i - 1])
            continue;
        list.r[0] = list.r[i];
        list.r[i] = list.r[i - 1];
        for (j = i - 2; list.r[0] < list.r[j]; j--)
        {
            list.r[j + 1] = list.r[j];
        }
        list.r[j + 1] = list.r[0];
#ifdef DEBUG
        showList(list);
#endif
    }
}
void SelectSort(SqList list)
{
    int i, j;
    int minIndex;

    for (i = 1; i <= list.length; i++)
    {
        minIndex = i;
        for (j = i + 1; j <= list.length; j++)
        {
            if (list.r[j] < list.r[minIndex])
                minIndex = j;
        }
        list.r[0] = list.r[minIndex];

        list.r[minIndex] = list.r[i];
        list.r[i] = list.r[0];
#ifdef DEBUG
        showList(list);
#endif
    }
}